﻿//Menu
$(document).ready(function() {
    $("ul.sf-menu").supersubs({
        minWidth: 12,   // minimum width of sub-menus in em units 
        maxWidth: 27,   // maximum width of sub-menus in em units 
        extraWidth: 1     // extra width can ensure lines don't sometimes turn over 
        // due to slight rounding differences and font-family 
    }).superfish();  // call supersubs first, then superfish, so that subs are 
    // not display:none when measuring. Call before initialising 
    // containing tabs for same reason.
});
// Change language
function changeLanguage(value, to) {
    var url = window.location.href;
    if (url.indexOf('/' + value) > 0) {
        url = url.replace('/' + value, '/' + to);
    }
    else {
        url = url + to + '/';
    }
    window.location = url;
}
//// 3 - MESSAGE BOX FADING SCRIPTS ---------------------------------------------------------------------

$(document).ready(function() {
    $(".close-yellow").click(function() {
        $("#message-yellow").fadeOut("slow");
    });
    $(".close-red").click(function() {
        $("#message-red").fadeOut("slow");
    });
    $(".close-blue").click(function() {
        $("#message-blue").fadeOut("slow");
    });
    $(".close-green").click(function() {
        $("#message-green").fadeOut("slow");
    });
});

// END ----------------------------- 3

// 1 - START DROPDOWN SLIDER SCRIPTS ------------------------------------------------------------------------

$(document).ready(function() {
    $(".showhide-account").click(function() {
        $(".account-content").slideToggle("fast");
        $(this).toggleClass("active");
        return false;
    });
});

$(document).ready(function() {
    $(".action-slider").click(function() {
        $("#actions-box-slider").slideToggle("fast");
        $(this).toggleClass("activated");
        return false;
    });
});

//  END ----------------------------- 1


$(function() {
    $.ajaxSetup({ cache: false });

    $('#toggle-all').click(function() {
        //
        if ($(this).attr('class') != "toggle-checked") {
            $('#mainform input[type=checkbox]').attr('checked', false);
        }
        //alert($(this).attr('class'));
        $('#mainform input').checkBox();
        $('#toggle-all').toggleClass('toggle-checked');
        $('#mainform input[type=checkbox]').checkBox('toggle');
        return false;
    });
    $('#mainform input:checkbox:not(#toggle-all)').click(function() {
        $('#toggle-all').removeClass('toggle-checked');
    });
    /* Custom javascripts for listing pages
    ============================================================*/

    //prompt for delete button
    $('.remove-btn').click(function(e) {
        e.preventDefault(); //prevent default action for anchor

        if (confirm("Confirm removed the selected records?")) {
            window.location = this.href;
        }
    });

    //prompt for reject button
    $('.reject-btn').click(function(e) {
        e.preventDefault(); //prevent default action for anchor

        if (confirm("Confirm reject the selected Post Property Request?")) {
            window.location = this.href;
        }
    });

    //prompt for approve button
    $('.approve-btn').click(function(e) {
        e.preventDefault(); //prevent default action for anchor

        if (confirm("Confirm approving the selected Post Property Request?")) {
            window.location = this.href;
        }
    });

    //bulk process action
    $('.action-invoke').click(function(e) {

        e.preventDefault(); //prevent default action for anchor
        
        //ensure at least one item is checked
        var fields = $("input[name='selected']").serializeArray();
        if (fields.length == 0) {
            alert('Please select at least one item.');
            return false;
        } else {

            //submit form
            $(".list_item_form").attr("action",this.href);
            
            $(".list_item_form").submit();
        }
    });
    //Sort by process action
    $('.action-sort').click(function(e) {

        e.preventDefault(); //prevent default action for anchor
       //submit form
        $(".list_item_form").attr("action", this.href);
        $(".list_item_form").submit();
        
    });

    //bulk process action
    $('.remove-sidecontent-btn').click(function(e) {

        e.preventDefault(); //prevent default action for anchor

        //submit form
        $("#delete_sidecontent_hook").attr("action", this.href);
        $("#delete_sidecontent_hook").submit();

    });

    //bulk process delete action
    $('.action-invoke-removed').click(function(e) {

        e.preventDefault(); //prevent default action for anchor

        //ensure at least one item is checked
        var fields = $("input[name='selected']").serializeArray();
        if (fields.length == 0) {
            alert('Please select at least one item.');
            return false;
        } else {

            if (confirm("Confirm removed the selected records?")) {
                $(".list_item_form").attr("action", this.href);
                $(".list_item_form").submit();
            }
        }
    });

    //bulk process reject post property request action
    $('.action-invoke-rejected').click(function(e) {

        e.preventDefault(); //prevent default action for anchor

        //ensure at least one item is checked
        var fields = $("input[name='selected[]']").serializeArray();
        if (fields.length == 0) {
            alert('Please select at least one item.');
            return false;
        } else {

            if (confirm("Confirm reject the selected Post Property Request(s)?")) {
                $(".list_item_form").attr("action", this.href);
                $(".list_item_form").submit();
            }
        }
    });


    //bulk process reject post property request action
    $('.action-invoke-approved').click(function(e) {

        e.preventDefault(); //prevent default action for anchor

        //ensure at least one item is checked
        var fields = $("input[name='selected[]']").serializeArray();
        if (fields.length == 0) {
            alert('Please select at least one item.');
            return false;
        } else {

            if (confirm("Confirm approve the selected Post Property Request(s)?")) {
                $(".list_item_form").attr("action", this.href);
                $(".list_item_form").submit();
            }
        }
    });


});
//Tooltips -->

$(function() {
	$('a.info-tooltip ').tooltip({
		track: true,
		delay: 0,
		fixPNG: true, 
		showURL: false,
		showBody: " - ",
		top: -35,
		left: 5
	});
});

function htmlspecialchars(str) {
    if (typeof (str) == "string") {
        str = str.replace(/&/g, "&amp;");
        str = str.replace(/"/g, "&quot;");
        str = str.replace(/'/g, "&rsquo;s");
        str = str.replace(/</g, "&lt;");
        str = str.replace(/>/g, "&gt;");
    }
    return str;
}

//set up
//Pretty Loader/
//styled select box script version 1 

$(document).ready(function() {
    $('.styledselect').selectbox({ inputClass: "selectbox_styled" });
    //
    $('.styledselect_form_2').selectbox({ inputClass: "styledselect_form_2" });
    //
    $('.styledselect_pages').selectbox({ inputClass: "styledselect_pages" });
});